﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel.Syndication;
using System.Xml;
namespace DM_RSS_Reader
{
    public class RSSReader
    {
        private SyndicationFeed mFeed;
        private string mURL;
        private XmlReader mReader;
        public RSSReader(string uri)
        {
            mReader = XmlReader.Create(uri);
            mFeed = SyndicationFeed.Load(mReader);
            mReader.Close();
        }
        public List<string> TryGetTitles()
        {
              List<string> title=new List<string>();
           

            
              
                foreach (SyndicationItem item in mFeed.Items)
                {
                    title.Add(item.Title.Text);

                }
               
            
           
            return title;
        }
        public List<string> TryGetSummaries()
        {
            List<string> summary = new List<string>();
          

            

                foreach (SyndicationItem item in mFeed.Items)
                {
                    summary.Add(item.Summary.Text);

                }

            
         
         
            return summary;
            
        }
      
        public List<DateTime> TryGetPostPublishedTimes()
        {
            List<DateTime> time = new List<DateTime>();
            try
            {

                foreach (SyndicationItem item in mFeed.Items)
                {
                 time.Add(item.PublishDate.DateTime);

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return time;
            
        }
        public string title
        {
            get
            {
                return mFeed.Title.Text;
            }
        }
        public DateTime GetLastUpdateTime
        {
            get
            {
                return mFeed.LastUpdatedTime.DateTime;
            }

        }
        public List<string> GetPostUri()
        {
            List<string> url = new List<string>() ;
            

                foreach (SyndicationItem item in mFeed.Items)
                {
                    url.Add(item.BaseUri.AbsoluteUri);
                }
            
            return url;
        }
       
    }
    




    }

